Skip to content

fix(miner): scope recordRateLimit to the core-billed rate-limit resource - #10201

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10005
Jul 31, 2026
Merged

fix(miner): scope recordRateLimit to the core-billed rate-limit resource#10201
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10005

Conversation

@bitfathers94

Copy link
Copy Markdown
Contributor

What

recordRateLimit in packages/loopover-miner/lib/opportunity-fanout.ts folded every response's
x-ratelimit-remaining into one number with Math.min, regardless of which GitHub rate-limit
resource billed the request. githubGetJson serves both the search endpoint (billed against the
small, per-minute search bucket) and the per-repo contents/list endpoints (billed against the
large, per-hour core bucket). Folding both meant a single /search/issues response pinned
summary.rateLimitRemaining to the search bucket's tiny remaining count, which sits under
discovery-throttle.ts's default 50 low-water-mark — so resolveThrottledConcurrency serialized
every subsequent policy-doc fetch in the run to one in-flight request, even though the core budget
those requests actually spend had thousands left.

Fix

recordRateLimit now reads the response's x-ratelimit-resource header and returns early (recording
neither rateLimitRemaining nor rateLimitResetAt) when that header is present and not core. A
response with no x-ratelimit-resource header at all — an older forge/proxy, or any existing test
fixture — is recorded exactly as before. The #9678 null/blank/non-numeric guard is preserved
verbatim. No public shape changed: CandidateIssueSummary.rateLimitRemaining now simply reflects the
core budget.

Tests

Added to test/unit/miner-opportunity-fanout.test.ts:

  • only a core-billed (or resource-header-less) x-ratelimit-remaining is folded into the summary
  • rateLimitResetAt is likewise scoped to core-billed responses
  • an absent x-ratelimit-resource header still records x-ratelimit-remaining (backward compatible)
  • a named regression test (REGRESSION: the search bucket's remaining budget does not pin the core fan-out to serial concurrency) that fails against the pre-fix code, asserting the observed max
    in-flight /contents/ requests exceeds 1 under concurrency: 5

Ran npx vitest run test/unit/miner-opportunity-fanout.test.ts test/unit/miner-opportunity-fanout-forge.test.ts test/unit/miner-opportunity-fanout-pagination.test.ts — all 56 tests pass, and coverage on the changed lines is 100% (branch-counted).

Closes #10005

GitHub bills the search endpoint and the per-repo contents/list requests
against two independent primary rate-limit resources, and reports each
response's resource in x-ratelimit-resource. Folding both into a single
Math.min'd rateLimitRemaining recorded the search bucket's small per-minute
allowance as the run's whole budget, pinning the core-budget-gated policy
fan-out to serial concurrency. Skip a response billed against a resource
other than core, while still recording one with no resource header at all.
@bitfathers94
bitfathers94 requested a review from JSONbored as a code owner July 31, 2026 12:21
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-31 12:30:51 UTC

2 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR scopes recordRateLimit to skip non-core-billed responses (e.g. the search endpoint's tiny per-minute bucket) so they no longer pin the shared rateLimitRemaining summary and serialize the core-budget-gated fan-out. The fix is applied at the correct layer (the shared recordRateLimit helper used by both search and contents/list calls) and is backward compatible when x-ratelimit-resource is absent. Tests directly exercise the described regression, including a concurrency-based regression test that fails pre-fix, and the diff closes issue #10005 as intended.

Nits — 3 non-blocking
  • nit: the large comment block in opportunity-fanout.ts:216-224 duplicates most of what's already stated in the PR description; consider trimming to the essential resource-skip rationale.
  • nit: the analogous recordRateLimit in packages/discovery-index/src/github-client.ts (shown in reference context) doesn't fold search results at all today, but if that changes in the future it will have the same fold-both-buckets bug — worth a cross-reference comment there for future maintainers.
  • Consider extracting the shared x-ratelimit-resource-aware recording logic if discovery-index/github-client.ts ever starts hitting the search endpoint, to avoid re-introducing this bug in a second place.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #10005
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 130 registered-repo PR(s), 92 merged, 3 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bitfathers94; Gittensor profile; 130 PR(s), 3 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: significant
Linked issue satisfaction

Addressed
The diff adds the exact required guard inside recordRateLimit, skipping remaining/reset recording when x-ratelimit-resource is present and not "core" while leaving header-absent responses recorded as before, preserving the #9678 guard and the CandidateIssueSummary shape. Tests cover core-only folding, reset scoping, backward-compatible absent-header behavior, and a regression test demonstrating re

Review context
  • Author: bitfathers94
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 130 PR(s), 3 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.53%. Comparing base (3884485) to head (d2b9cc8).

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #10201       +/-   ##
===========================================
- Coverage   92.21%   80.53%   -11.69%     
===========================================
  Files         934      283      -651     
  Lines      114178    59025    -55153     
  Branches    27593     8767    -18826     
===========================================
- Hits       105294    47535    -57759     
- Misses       7582    11199     +3617     
+ Partials     1302      291     -1011     
Flag Coverage Δ
backend 100.00% <100.00%> (+4.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/loopover-miner/lib/opportunity-fanout.ts 100.00% <100.00%> (ø)

... and 783 files with indirect coverage changes

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit d308a9c into JSONbored:main Jul 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

miner(discover): the search endpoint's rate-limit budget is folded into the core budget, pinning --search fan-out to serial concurrency

1 participant